# -*- mode: shell-script -*-
# Shell functions for downloading and extracting a RHEL or RHEL clone RPM

# Arguments:
# $1: Linux distribution name
# $2: Linux distribution version (major.minor)
# $3: architecture
function get_srpm_urls() {
    local arch distro releasever releasevermajor releaseverminor

    distro="$1"
    releasever="$2"
    arch="$3"
    IFS=.
    set -- "$2"
    unset IFS
    releasevermajor="$1"
    releaseverminor="$2"

    case "$distro" in
	"CentOS"*)
	    case $releasever in
		5.*|6.[01])
		    echo "http://vault.centos.org/${releasever}/os/SRPMS http://vault.centos.org/${releasever}/updates/SRPMS";;
		[67].*)
		    echo "http://vault.centos.org/${releasever}/os/Source/SPackages http://vault.centos.org/${releasever}/updates/Source/SPackages";;
	    esac
	    ;;
	"Red Hat Enterprise Linux"*)
	    case $releasever in
		[56].*)
		    echo "http://ftp.redhat.com/pub/redhat/linux/enterprise/${releasevermajor}Server/en/os/SRPMS http://ftp.redhat.com/redhat/rhel/rc/7/Server/source/tree/Packages";;
	    esac
	    ;;
	"Oracle Linux Server")
	    echo "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/${releaseverminor}/base/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/latest/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/UEK/latest/${arch}/getPackageSource"
	    ;;
	"Scientific Linux")
	    case $releasever in
		5.*)
		    echo "http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor";;
		6.*)
		    echo "http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor";;
	    esac
	    ;;
	*)
	    echo "Unknown type of distribution: $distro" >&2
	    return 1
	    ;;
    esac
}

# Arguments:
# $1: Linux distribution name
# $2: Linux distribution version (major.minor)
# $3: architecture
function get_rpm_urls() {
    local arch distro releasever releasevermajor releaseverminor

    distro="$1"
    releasever="$2"
    arch="$3"
    IFS=.
    set -- "$2"
    unset IFS
    releasevermajor="$1"
    releaseverminor="$2"

    case "$distro" in
	"CentOS"*)
	    case $releasever in
		5.*)
		    echo "http://vault.centos.org/${releasever}/os/${arch}/CentOS http://vault.centos.org/${releasever}/updates/${arch}/RPMS";;
		6.[01])
		    echo "http://vault.centos.org/${releasever}/os/${arch}/Packages http://vault.centos.org/${releasever}/updates/${arch}/Packages";;
		[67].*)
		    echo "http://vault.centos.org/${releasever}/os/${arch}/Packages http://vault.centos.org/${releasever}/updates/${arch}/Packages";;
	    esac
	    ;;
	"Red Hat Enterprise Linux"*)
	    echo "";;
	"Oracle Linux Server")
	    echo "http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/${releaseverminor}/base/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/latest/${arch}/getPackageSource http://public-yum.oracle.com/repo/OracleLinux/OL${releasevermajor}/UEK/latest/${arch}/getPackageSource"
	    ;;
	"Scientific Linux")
	    case $releasever in
		5.*)
		    echo "http://ftp.scientificlinux.org/linux/scientific/$releasevermajor$releaseverminor/SRPMS/vendor";;
		6.*)
		    echo "http://ftp.scientificlinux.org/linux/scientific/$releasever/SRPMS/vendor";;
	    esac
	    ;;
	*)
	    echo "Unknown distribution type: $distro" >&2
	    return 1
	    ;;
    esac
}
